package com.lagou.edu.course.api.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 课程状态
 */
public enum CourseStatus {
    /**
     * 草稿
     */
    DRAFT(0, "草稿"),

    /**
     * 上架
     */
    PUTAWAY(1, "上架");

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 课程名称
     */
    private String name;


    CourseStatus(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    private static final Map<Integer, CourseStatus> CACHE = new HashMap<Integer, CourseStatus>();

    static {
        for (CourseStatus val : CourseStatus.values()) {
            CACHE.put(val.getCode(), val);
        }
    }

    /**
     * 根据code值来转换为枚举类型
     */
    public static CourseStatus parse(Integer code) {
        return CACHE.get(code);
    }

}
